package com.mes.cloud.controller;

import com.github.pagehelper.PageInfo;
import com.mes.cloud.dto.BmeBcFiledDTO;
import com.mes.cloud.service.BmeBcFiledService;
import com.mes.cloud.util.CommPager;
import com.mes.cloud.util.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * <BC_Filed基础表>
 *
 * @author xhy
 * @version 1.0
 * @date 2019/05/09 16:00
 */
@Api(tags = "BmeBcFiledController", description = "BcFiled配置")
@RestController
@RequestMapping("/bmeBcFiled")
public class BmeBcFiledController {
    private static final Logger LOGGER = LoggerFactory.getLogger(BmeBcFiledController.class);

    @Autowired
    private BmeBcFiledService bmeBcFiledService;

    /**
     * <根据条件获取BC_Filed基础表列表>
     *
     * @param map
     * @return
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "列表 无分页")
    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    public JSONResult getBmeBcFiledList(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcFiledController:Method findList :inParam map: " + map.toString());
        JSONResult jsonResult = null;
        try {
            List<BmeBcFiledDTO> bmeBcFiledList = bmeBcFiledService.getBmeBcFiledList(map);
            jsonResult = JSONResult.success(bmeBcFiledList);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method findList :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController:Method findList :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * bme_bc_pickmap表中pickbc字段对应
     * 根据bccode  pickmapcode查找字段列表
     *
     * @param map
     * @return
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "列表 无分页")
    @RequestMapping(value = "/findListByCodePickmapCode", method = RequestMethod.POST)
    public JSONResult findListByCodePickmapCode(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcFiledController:Method findListByCodePickmapCode :inParam map: " + map.toString());
        JSONResult jsonResult = null;
        try {
            List<BmeBcFiledDTO> bmeBcFiledList = bmeBcFiledService.findListByCodePickmapCode(map);
            jsonResult = JSONResult.success(bmeBcFiledList);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method findListByCodePickmapCode :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController:Method findListByCodePickmapCode :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <根据条件获取BC_Filed基础表分页列表>
     *
     * @param map
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "列表 分页")
    @RequestMapping(value = "/findPageList", method = RequestMethod.POST)
    public JSONResult getBmeBcFiledPageList(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcFiledController :Method findPageList:inParam map: " + map.toString());
        JSONResult jsonResult = null;
        try {
            CommPager<BmeBcFiledDTO> pageInfo = bmeBcFiledService.getBmeBcFiledListPage(map);
            jsonResult = JSONResult.success(pageInfo);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController :Method findPageList:OutParam E: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController :Method findPageList :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <获取BC_Filed基础表的最大记录数>
     *
     * @param map
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "获取最大记录数")
    @RequestMapping(value = "/getCount", method = RequestMethod.POST)
    public JSONResult getBmeBcFiledCount(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcFiledController:Method getCount:inParam map: " + map.toString());
        JSONResult jsonResult = null;
        try {
            long count = bmeBcFiledService.getBmeBcFiledCount(map);
            jsonResult = JSONResult.success(count);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method getCount:OutParam E: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController:Method getCount :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <新增BC_Filed基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JSONResult insertBmeBcFiled(@RequestBody BmeBcFiledDTO bmeBcFiledDTO) {
        LOGGER.info("Class BmeBcFiledController:Method insert :inParam bmeBcDTO: " + bmeBcFiledDTO.toString());
        JSONResult jsonResult = null;
        try {
            long count = bmeBcFiledService.insertBmeBcFiled(bmeBcFiledDTO);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method insert:OutParam E: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController:Method insert :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <更新BC_Filed基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "更新")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JSONResult updateBmeBcFiled(@RequestBody BmeBcFiledDTO bmeBcFiledDTO) {
        LOGGER.info("Class BmeBcFiledController:Method update :inParam bmeBcDTO: " + bmeBcFiledDTO.toString());
        JSONResult jsonResult = null;
        try {
            long count = bmeBcFiledService.updateBmeBcFiled(bmeBcFiledDTO);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method update:OutParam E: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController:Method update :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <删除BC_Filed基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JSONResult delBmeBcFiledByPrimaryKey(@RequestBody BmeBcFiledDTO bmeBcFiledDTO) {
        LOGGER.info("Class BmeBcFiledController:Method delete :inParam bmeBcFiledDTO: " + bmeBcFiledDTO);
        JSONResult jsonResult = null;
        try {
            long count = bmeBcFiledService.delBmeBcFiledById(bmeBcFiledDTO.getId());
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method delete:OutParam E: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController:Method delete :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * <根据bme_bc_join基础表标识获取bme_bc_join基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public JSONResult getBmeBcJoinByPrimaryKey(@RequestBody BmeBcFiledDTO bmeBcFiledDTO) {
        LOGGER.info("Class BmeBcFiledController:Method get :inParam bmeBcFiledDTO: " + bmeBcFiledDTO);
        JSONResult jsonResult = null;
        try {
            BmeBcFiledDTO bmeBcFiledDTOs = bmeBcFiledService.getBmeBcFiledById(bmeBcFiledDTO.getId());
            jsonResult = JSONResult.success(bmeBcFiledDTOs);
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method get :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController :Method get :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * 对BC_Filed基础表标进行批量删除操作
     *
     * @param map
     * @return long
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "删除 批量")
    @RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
    public JSONResult batchDelete(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcFiledController:Method batchDelete :inParam map: " + map);
        JSONResult jsonResult = null;
        try {
            jsonResult = JSONResult.success(bmeBcFiledService.batchDelete(map));
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method batchDelete :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController :Method batchDelete :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    /**
     * 删除BC_Filed基础表根据pid
     *
     * @param map
     * @return long
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "启用禁用")
    @RequestMapping(value = "/enable", method = RequestMethod.POST)
    public JSONResult enable(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcFiledController:Method updateEnable :inParam map: " + map);
        JSONResult jsonResult = null;
        try {
            long count = bmeBcFiledService.enable(map);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(0, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcFiledController:Method updateEnable:OutParam E: " + e.getMessage());
            jsonResult = JSONResult.fail(0, e.getMessage());
        }
        LOGGER.info("Class BmeBcFiledController:Method updateEnable :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }

    @ApiOperation(value = "导出")
    @RequestMapping(value = "/exportFile", method = RequestMethod.GET)
    public JSONResult exportFile(@RequestParam Map<Object, Object> map, HttpServletResponse response) {
        JSONResult result;
        try {
            bmeBcFiledService.exportFile(map, response);
            result = JSONResult.success();
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            result = JSONResult.fail(201, e.getMessage());
        }
        return result;
    }

    @ApiOperation(value = "导入")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public JSONResult importExcel(@RequestParam MultipartFile file) {
        JSONResult result;
        try {
            result = JSONResult.success(bmeBcFiledService.importExcel(file));
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            result = JSONResult.fail(201, e.getMessage());
        }
        return result;
    }
}
